#![cfg_attr(
  all(not(debug_assertions), target_os = "windows"),
  windows_subsystem = "windows"
)]
// mod mail_sender;
// use crate::mail_sender::MailSender;

use base64::{engine::general_purpose, Engine as _};
use calamine::{open_workbook_auto_from_rs, DataType};
use std::io::Cursor;
use tauri::{CustomMenuItem, Menu, Submenu};
struct Sender {
  name: String,
  email: String,
  password: String,
  smtp_server_path: String,
  send_title: String,
}

#[tauri::command]
fn send_mails(sender: String, base64: String) -> String {
  let bytes = general_purpose::STANDARD.decode(base64).unwrap();
  // 创建一个内存中的读取器
  let mut workbook = open_workbook_auto_from_rs(Cursor::new(bytes));

  // 遍历工作簿中的所有工作表
  format!("Hello, {}!", sender)
}
fn main() {
  let context = tauri::generate_context!();
  tauri::Builder::default()
    .invoke_handler(tauri::generate_handler![send_mails])
    .menu(Menu::new().add_submenu(Submenu::new(
      "File",
      Menu::new().add_item(CustomMenuItem::new("close", "退出").accelerator("cmdOrControl+Q")),
    )))
    .on_menu_event(|event| match event.menu_item_id() {
      "close" => {
        event.window().close().unwrap();
      }
      _ => {}
    })
    .run(context)
    .expect("error while running tauri application");
}
